import request from '@/utils/request'

export interface DeptVO {
  id?: number
  name: string
  parentId: number
  status: number
  sort: number
  code: string
  type: number
  leaderUserId: number
  phone: string
  email: string
  createTime: Date
}

// 查询部门（精简)列表
export const getSimpleDeptList = (): Promise<DeptVO[]> => {
  return request({
    url: '/system/dept/simple-list',
    method: 'GET',
  })
}

// 查询部门列表
export const getDeptPage = (params: any) => {
  return request({
    url: '/system/dept/list',
    method: 'GET',
    params,
  })
}

// 查询部门详情
export const getDept = (id: number) => {
  return request({
    url: `/system/dept/get?id=${id}`,
    method: 'GET',
  })
}
// 新增部门/修改部门
export const saveOrUpdate = (data: DeptVO) => {
  return request({
    url: '/system/dept/saveOrUpdate',
    method: 'POST',
    data,
  })
}

// 新增部门
export const createDept = (data: DeptVO) => {
  return request({
    url: '/system/dept/create',
    method: 'POST',
    data,
  })
}

// 修改部门
export const updateDept = (params: DeptVO) => {
  return request({
    url: '/system/dept/update',
    method: 'POST',
    data: params,
  })
}

// 删除部门
export const deleteDept = (id: number) => {
  return request({
    url: `/system/dept/delete?id=${id}`,
    method: 'DELETE',
  })
}
// 根据parentId 读取下一个node
export const getNextChildNode = (data: DeptVO) => {
  return request({
    url: '/system/dept/getNextChildNode',
    method: 'POST',
    data,
  })
}
// 移动
export const getMove = (data: any) => {
  return request({
    url: '/system/dept/getMove',
    method: 'POST',
    data,
  })
}
